package design;

public class Singleton {
    private Singleton() {}
    private static volatile Singleton instance;

    //静态类
    public static final Singleton instance1 = new Singleton();

    /**
     * 懒汉式
     */
    public static Singleton getInstance() {
        synchronized (Singleton.class) {
            if (instance == null) {
                instance = new Singleton();
            }
        }
        return instance;
    }
}
